﻿using System;
using System.Collections;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Linq;
using System.Web.Script.Serialization;
using System.Net;
using System.Text;
using System.Xml;
using System.IO;
using System.Xml.XPath;

namespace EpiMapit.Web
{
    /// <summary>
    /// Summary description for $codebehindclassname$
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    public class KmlHandler : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            //var kmlUrl = Uri.UnescapeDataString(context.Request.QueryString.ToString());

            //WebClient web = new WebClient();
            //byte[] data = web.DownloadData(kmlUrl);

            //XmlDocument doc = new XmlDocument();
            //doc.Load(new MemoryStream(data));

            //context.Session["CurrentKml"] = doc;
           
            var response = new KmlDataResponse()
            {
                Dates = new DateTime[] { new DateTime(2009, 1, 1), new DateTime(2009, 1, 2), new DateTime(2009, 1, 3) },
                Distances = new float[] { 1, 50, 100 },
                FirstKml = "http://dl.getdropbox.com/u/579084/gris.kml",                
            };

            var jsSerializer = new JavaScriptSerializer();
            var result = jsSerializer.Serialize(response);

            context.Response.ContentType = "text/json";
            context.Response.Write(result);
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}
